import request from '../../utils/request2';



import urls from '../../utils/urls';
//配置信息
const docking = {
  appId: "hwyxgl",
  url: "http://10.81.106.123",
  client_secret:"77a48b79b41a46c7b80ee4fa377d6dc9"
}

interface LoginParams {
  username: string;
  password: string;
}

let processName = urls.online;
let processVerification = urls.verification;

enum Api {
  Login = '/login',
  Logout = '/logout',
  GetUserInfo = '',
  GetPermCode = 'other/jwt/getJWT',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams) {
  return request({
    url:  processName + Api.Login,
    params:params,
    method: 'get',
  })
}



/**
 * @description: getUserInfo
 */
export function getUserInfo(params:object) {
  return request({
    url:  Api.GetUserInfo,
    params:params,
    method: 'get',
  })
}

/**
 * @description: getUserInfo
 */
 export function GetPermCode(params:object) {
  return request({
    url:  processName + Api.GetPermCode,
    params:params,
    method: 'get',
  })
}

export function GetTokenFn(code) {
  return request({
    url:   docking.url+'/idp/oauth2/getToken?client_id='+docking.appId+'&grant_type=authorization_code&code='+code+'&client_secret='+docking.client_secret,
    method: 'post',
  })
}

export async function GetNewInfo(params) {
  return request({
    url:   docking.url+'/idp/oauth2/getUserInfo?access_token='+params.access_token+'&client_id='+docking.appId+'&uid='+params.uid,
    method: 'get',
  })
}

// 获取token

export async function GetCode() {
  return request({
    url:   docking.url+'/idp/oauth2/authorize?redirect_uri=http://10.81.106.123&state=123&client_id='+docking.appId+'&response_type=code',
    method: 'get',
  })
}




export function doLogout() {
  return request({
    url:  processName + Api.Logout,
    method: 'get',
  })
}

